//
//  ShoppingMallVc.m
//  zhangGuangTianXia
//
//  Created by Mac on 2017/11/15.
//  Copyright © 2017年 tangtangchitangtang. All rights reserved.
//

#import "ShoppingMallVc.h"
#import "ShoppingMallCollectCell.h" //cell

@interface ShoppingMallVc ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *bannerContentView;  //装Banner的view

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UICollectionView *collectView;

@property (nonatomic,strong)NSArray *leftDataArr; //左边列表数据

@property (nonatomic,strong)NSArray *rightDataArr;//右边列表数据

@property (nonatomic,assign)NSInteger leftIndex;  //左边列表索引

@property (nonatomic,assign)NSInteger rightIndex; //右边索引

@property (nonatomic,strong)UIView   *tableLeftView;//列表cell左边的蓝条

@end

@implementation ShoppingMallVc

- (void)viewDidLoad {
    [super viewDidLoad];

    self.leftIndex = -1;
    
    self.rightIndex= -1;
    
    self.leftDataArr = @[@"鲜花园艺",@"饰品",@"食品",@"生鲜",@"汽车摩托",@"医药",@"图书",@"通信",@"洗护",@"乐器"];
 
    self.tableView.rowHeight = 60;
    
    [self loadBanner];
    
    [self.tableView reloadData];
    
    [self.collectView reloadData];
}


- (void)loadBanner{


    [LYTools addRotationView:CGRectMake(0, 0, _mainW, self.bannerContentView.frame.size.height) :@[@"http://pic69.nipic.com/file/20150609/9252150_174125118561_2.jpg",@"http://pic26.photophoto.cn/20130312/0037037526572944_b.jpg"] :_zhanweiImageData :self.bannerContentView :^(NSInteger value) {
        
        
        
        
    }];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.leftDataArr.count;


}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //这里用直接用代码控制cell 只是样式 不重要 难得再新建个文件  //这里数据理论上不多 为了方便 先不重用啦 啊哈哈.. 一切求清晰 精简

    NSString *cellID = @"BaseTableViewCell";
    
//    BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//    
//    if(cell==nil)
//    {
//        cell = [[BaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
//    }

    BaseTableViewCell *cell = [[BaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    
    cell.textLabel.text = self.leftDataArr[indexPath.row];
    
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    
    cell.textLabel.textColor     = [UIColor grayColor];
    
    cell.backgroundColor         = [UIColor groupTableViewBackgroundColor];
    
    
    
    
    //底部线条
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor = [UIColor whiteColor];
    [cell addSubview:footerView];
    [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
      
        make.height.mas_equalTo(1);
        make.left.offset(0);
        make.bottom.offset(0);
        make.right.offset(0);
    }];
    
    //判断是否选中
    if(indexPath.row==self.leftIndex)
    {
        _tableLeftView= [[UIView alloc] init];
        _tableLeftView.backgroundColor = [UIColor blueColor];
        [cell addSubview:_tableLeftView];
        [_tableLeftView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.mas_equalTo(2);
            make.left.offset(0);
            make.top.offset(0);
            make.bottom.offset(0);
        }];
        
        cell.textLabel.textColor     = [UIColor blueColor];
        cell.backgroundColor         = [UIColor whiteColor];
        
    }
  
    return cell;
 
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    self.leftIndex = indexPath.row;
    
    [self.tableView reloadData];

}




 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 50;;
}


// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{


    ShoppingMallCollectCell *cell = [ShoppingMallCollectCell ShoppingMallCollectCell:collectionView :indexPath];

    return cell;

}




//设置item的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    CGFloat itemW = self.collectView.frame.size.width/3-10;
    
    CGFloat itemH = itemW+10;
    
    return CGSizeMake(itemW , itemH);
}


@end
